package ko;

import java.util.ArrayList;

import ko.util.IHitTypes;

public class KHitDetector {
	
	public static void ScanningLayer(KEntity entity) {
		if (!(entity instanceof IHitTypes)
		|| entity.hitLayers == null 
		|| entity.hitLayers.size() < 1) return;
		for (String layer : entity.hitLayers) {
			Detect(entity, K.game.getRenderByLayer(layer));
		}
	}
	
	private static void Detect(KEntity objA, ArrayList<KEntity> list) {
		if (list == null || list.size() < 1 ) return;
		KEntity objB;
		int index = list.size();
		while (index-- > 0) {
			objB = list.get(index);
			if (objA == objB) continue;
			
			hitTypes((IHitTypes)objA , objB);
		}
	}
	
	private static void hitTypes(IHitTypes objA, KEntity objB) {
		if (objB instanceof KRectangleEntity) {
			objA.vsOBB((KRectangleEntity)objB);
			
		}else if (objB instanceof KCircleEntity) {
			objA.vsCircle((KCircleEntity)objB );
		}
	}
}
